<?= "<?\n" ?>

require_once(dirname(__FILE__) . '/../../libs/bf/bf.php');
require(dirname(__FILE__) . '/config/index.php');

$models = dirname(__FILE__) . '/models';
$files = scandir($models);
foreach ($files as $file)
	if (preg_match('/\.php$/', $file) && is_file($models . '/' . $file))
		require_once($models . '/' . $file);

$validators = dirname(__FILE__) . '/validators';
$files = scandir($validators);
foreach ($files as $file)
	if (preg_match('/\.php$/', $file) && is_file($validators . '/' . $file))
		require_once($validators . '/' . $file);

$models = $validators = $files = null;

bf::$application->runtime->db_connect = create_function(
	'$db_config',
	'return new bf_db_' . bf::$application->config['db-engine'] . '($db_config);'
);

bf::$application->runtime->mailer_connect = create_function(
	'$mailer_config',
	'return new bf_htmail_' . bf::$application->config['mailer-engine'] . '($mailer_config);'
);

bf::$http->disable_caching();

bf::$application->runtime->db = call_user_func(bf::$application->runtime->db_connect, bf::$application->config['db']);

$sql_init = dirname(__FILE__) . '/config/db.' . bf::$application->config['db-engine'] . '.init.sql.php';
if (is_file($sql_init)) {
	$sql_init_view = new bf_view(array(
		'location' => dirname($sql_init),
		'file' => basename($sql_init),
	));
	$sql_init_view->db = bf::$application->runtime->db;
	ob_start();
	$sql_init_view->render();
	$sql_init = preg_split('/\s*--\s*go/', ob_get_contents());
	ob_end_clean();
	foreach ($sql_init as $sql)
		bf::$application->runtime->db->query($sql);
}

$sql = $sql_init = $sql_init_view = null;

bf::$application->runtime->mailer = call_user_func(bf::$application->runtime->mailer_connect, bf::$application->config['htmail']);

<?= '?>' ?>